using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace CPlatePrintSys.Domain.Models
{
    /// <summary>
    /// 取整规则配置
    /// </summary>
    public class RoundingRuleConfig
    {
        /// <summary>
        /// 默认取整规则
        /// </summary>
        public string Default { get; set; } = "4舍5入";

        /// <summary>
        /// 各加工阶段的取整规则
        /// </summary>
        public Dictionary<string, string> Stages { get; set; } = new Dictionary<string, string>();

        /// <summary>
        /// 获取指定阶段的取整规则，如果没有指定则返回默认规则
        /// </summary>
        public string GetRoundingRule(string stage)
        {
            if (Stages.ContainsKey(stage))
                return Stages[stage];
            return Default;
        }
    }

    /// <summary>
    /// 图层颜色配置
    /// </summary>
    public class LayerColorConfig
    {
        /// <summary>
        /// 划线层颜色（默认绿色）
        /// </summary>
        public string LineLayerColor { get; set; } = "#00FF00";

        /// <summary>
        /// 印字层颜色（默认橙色）
        /// </summary>
        public string TextLayerColor { get; set; } = "#FFA500";

        /// <summary>
        /// 信息层颜色（默认蓝色）
        /// </summary>
        public string InfoLayerColor { get; set; } = "#0000FF";
    }

    /// <summary>
    /// 输出目录配置
    /// </summary>
    public class OutputDirectoryConfig
    {
        /// <summary>
        /// 输出目录路径
        /// </summary>
        public string OutputPath { get; set; } = @"\\192.168.1.2\share\C-plate\";

        /// <summary>
        /// 是否启用自动备份
        /// </summary>
        public bool EnableBackup { get; set; } = true;

        /// <summary>
        /// 备份保留天数
        /// </summary>
        public int BackupRetentionDays { get; set; } = 30;
    }

    /// <summary>
    /// 接口配置
    /// </summary>
    public class InterfaceConfig
    {
        /// <summary>
        /// CadWin共享目录地址
        /// </summary>
        public string CadWinSharePath { get; set; } = @"\\192.168.2.3\CADWin\";

        /// <summary>
        /// KMACS接口HTTP方法
        /// </summary>
        public string KmacsHttpMethod { get; set; } = "GET";

        /// <summary>
        /// KMACS接口地址
        /// </summary>
        public string KmacsApiUrl { get; set; } = "http://192.168.1.0/biz/getInfo";

        /// <summary>
        /// 接口超时时间（秒）
        /// </summary>
        public int TimeoutSeconds { get; set; } = 30;

        /// <summary>
        /// 是否启用接口缓存
        /// </summary>
        public bool EnableCache { get; set; } = true;

        /// <summary>
        /// 缓存过期时间（分钟）
        /// </summary>
        public int CacheExpirationMinutes { get; set; } = 10;
    }

    /// <summary>
    /// 全局配置键常量
    /// </summary>
    public static class GlobalConfigKeys
    {
        public const string RoundingRule = "RoundingRule";
        public const string LayerColor = "LayerColor";
        public const string OutputDirectory = "OutputDirectory";
        public const string InterfaceConfig = "InterfaceConfig";
    }

    /// <summary>
    /// 取整规则选项
    /// </summary>
    public static class RoundingRuleOptions
    {
        public const string FourRoundFiveUp = "4舍5入";
        public const string OneRoundTwoUp = "1舍2入";
        public const string TwoRoundThreeUp = "2舍3入";
        public const string ThreeRoundFourUp = "3舍4入";
        public const string FiveRoundSixUp = "5舍6入";
        public const string SixRoundSevenUp = "6舍7入";
        public const string SevenRoundEightUp = "7舍8入";
        public const string EightRoundNineUp = "8舍9入";

        public static List<string> GetAllOptions()
        {
            return new List<string>
            {
                FourRoundFiveUp,
                OneRoundTwoUp,
                TwoRoundThreeUp,
                ThreeRoundFourUp,
                FiveRoundSixUp,
                SixRoundSevenUp,
                SevenRoundEightUp,
                EightRoundNineUp
            };
        }
    }
} 